#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 15:12
# @Author: 刘航
# @Email: xxx@gmail.com
# @File：add_cule_page.py

"""
添加线索模块
"""
from selenium.webdriver.common.by import By
from pages.cus_mag_pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class AddCulePage(BasePage):
    contacts_locator = (By.ID,"contacts_name") #联系人姓名
    mobile_locator = (By.ID,"mobile") #手机
    company_locator = (By.XPATH,'//*[@id="name"]') #公司名称
    save_locator = (By.XPATH,"/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td/input[1]")
    position_locator = (By.NAME, "position")  # 职位
    input_large_locator = (By.CLASS_NAME, "input-large")  # 详细地址信息
    nextstep_time_locator = (By.ID, "nextstep_time")  # 下次联系时间
    email_locator = (By.NAME, "email")
    nextstep_con_locator = (By.ID, "nextstep")  # 下次联系内容
    description_locator = (By.ID, "description") #描述
    source_locator = (By.ID, "source") #来源
    province_locator = (By.NAME, "address['state']")  # 选择省
    city_locator = (By.NAME, "address['city']")  # 市
    area_locator = (By.NAME, "address['area']")
    saltname_locator = (By.NAME, "saltname")
    clues_pool_locator = (By.ID,"remove")

    def contacts_input(self,contacts_name):
        """联系人姓名"""
        self.driver.find_element(*self.contacts_locator).send_keys(contacts_name)

    def company_input(self,company_name):
        """公司名称"""
        self.driver.find_element(*self.company_locator).send_keys(company_name)

    def mobile_input(self,mobile_num):
        """手机号"""
        self.driver.find_element(*self.mobile_locator).send_keys(mobile_num)

    def save_click(self):
        """保存"""
        self.driver.find_element(*self.save_locator).click()

    def position_name(self,position):
        """职位"""
        self.driver.find_element(*self.position_locator).send_keys(position)

    def large_add(self,large):
        """详细地址"""
        self.driver.find_element(*self.input_large_locator).send_keys(large)

    def nextstep_time(self,tnextstep):
        """下次联系时间"""
        self.driver.find_element(*self.nextstep_time_locator).send_keys(tnextstep)

    def email_name(self,email):
        """邮箱"""
        self.driver.find_element(*self.email_locator).send_keys(email)

    def nextstep_con(self,cnextstep):
        """下次联系内容"""
        self.driver.find_element(*self.nextstep_con_locator).send_keys(cnextstep)

    def description_con(self,description):
        """备注"""
        self.driver.find_element(*self.description_locator).send_keys(description)

    def source_select(self,source):
        """选择来源"""
        source_element = self.driver.find_element(*self.source_locator)
        Select(source_element).select_by_visible_text(source)

    def province_select(self,province):
        """选择省份"""
        source_element = self.driver.find_element(*self.province_locator)
        Select(source_element).select_by_visible_text(province)

    def city_select(self,city):
        """选择市"""
        source_element = self.driver.find_element(*self.city_locator)
        Select(source_element).select_by_visible_text(city)

    def area_select(self,area):
        """选择区"""
        source_element = self.driver.find_element(*self.area_locator)
        Select(source_element).select_by_visible_text(area)

    def saltname_select(self,saltname):
        """尊称"""
        source_element = self.driver.find_element(*self.saltname_locator)
        Select(source_element).select_by_visible_text(saltname)

    def clues_pool(self):
        """线索池"""
        self.driver.find_element(*self.clues_pool_locator).click()
        self.driver.switch_to.alert.accept()


    def add_cule_func(self,company_name,contacts_name,mobile_num):
        """添加线索函数，必填项"""
        self.contacts_input(contacts_name) #联系人姓名
        self.company_input(company_name) #公司名称
        self.mobile_input(mobile_num) #电话号码
        self.save_click() #保存

    def add_cule_pool(self,company_name,contacts_name,mobile_num):
        """添加线索函数,到线索池"""
        self.contacts_input(contacts_name) #联系人姓名
        self.company_input(company_name) #公司名称
        self.mobile_input(mobile_num) #电话号码
        self.clues_pool() #添加到线索池
        self.save_click() #保存